package com.Arsanesia.TempleRush.Models;

import com.Arsanesia.TempleRush.Views.Screens.AbstractScreen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;

public class Scenery {
	public final float GROUND_X;
	public final float GROUND_Y;
	public final float GRASS_X;
	public final float GRASS_Y;
	public final float MOUNTAIN_X;
	public final float MOUNTAIN_Y;
	public final float GROUNDTOLERANCE = 10f;
	private final float GRASSTOLERANCE = 13f;
	
	private Image ground;
	private Image grass;
	private Image mountain;
	private Image background;
	private Image moon;
	private Image tree1,tree2;
	private Color bgColor;
	private Color defaultColor;

	
	public Scenery(TextureAtlas atlas){
		//set up background
		background = new Image(atlas.createSprite("background"));
		tree1 = new Image(atlas.createSprite("pohon", 0));
		tree2 = new Image(atlas.createSprite("pohon", 1));
		//store the default color
		defaultColor = new Color(background.getColor());
		//set background color
		defaultColor.g *=0;
		defaultColor.r *= 0.07;
		defaultColor.b *= 0.07;
		background.setColor(new Color(defaultColor));
		
		//setup scene
		ground = new Image(atlas.findRegion("ground"));
		grass = new Image(atlas.findRegion("grass"));
		mountain = new Image(atlas.findRegion("mountain"));
        moon = new Image(new TextureRegion(atlas.createSprite("bulan")));

		//initialize points
		GROUND_X = 0; GROUND_Y = 0;
		GRASS_X = 0; GRASS_Y = AbstractScreen.VIEWPORT_DEFAULTHEIGHT/8 - GROUNDTOLERANCE;
		MOUNTAIN_X = 0; MOUNTAIN_Y = GRASS_Y+grass.getHeight()-GRASSTOLERANCE;//AbstractScreen.VIEWPORT_DEFAULTHEIGHT/4+20;
		//set the positions
		ground.setPosition(GROUND_X, GROUND_Y);
		grass.setPosition(GRASS_X, GRASS_Y);
		mountain.setPosition(MOUNTAIN_X, MOUNTAIN_Y);
		tree1.setPosition(-30, MOUNTAIN_Y);
		tree2.setPosition(AbstractScreen.VIEWPORT_DEFAULTWIDTH-100, MOUNTAIN_Y);
		
		
	}
	public float groundHeight(){
		return this.ground.getHeight();
	}
	public Image getMoon(){
		return this.moon;
	}
	public void addSceneToStage(Stage stage){
		//add to stage
		stage.addActor(background);
		stage.addActor(moon);
		stage.addActor(mountain);
		stage.addActor(tree1);
		stage.addActor(tree2);
		stage.addActor(ground);
		stage.addActor(grass);
	}
	public void decrementBgColor(float decremental){
		//if(bgColor.r>defaultColor.r && bgColor.b>defaultColor.b)
//		bgColor.r -= 10;
//		bgColor.b -=10;
			//bgColor = new Color(bgColor.r-10,bgColor.g, bgColor.b-10, bgColor.a);
		
		float r = defaultColor.r + decremental * 255;
		float g = defaultColor.g  + decremental * 255;
		float b = defaultColor.b + decremental * 255;
		bgColor = new Color(r,g,b,defaultColor.a);
		background.setColor(new Color(bgColor));
	}

}
